function buildRequest(req) {
	return new (function(r) {
		var me = this;
		me['src'] = r;
		me['request'] = {};
		me.request.body = r.get('request.body');
		me['methodPath'] = r.get('request.methodPath');
		me['requestPath'] = me['methodPath'];
		me['paramsMap'] = {};

		(function() {
			var parts = me.methodPath.split('?');
			me['requestPath'] = parts[0];
			if (parts.length > 1) {
				var paramTxt = parts[1];
				var params = paramTxt.split('&');
				for (var i = 0; i < params.length; i++) {
					var param = params[i];
					var paramInfo = param.split('=');
					if (paramInfo.length == 2) {
						if (typeof (me.paramsMap[decode(paramInfo[0])]) == 'undefined') {
							me.paramsMap[decode(paramInfo[0])] = [];
						}
						me.paramsMap[decode(paramInfo[0])]
								.push(decode(paramInfo[1]));
					}
				}
			}
		})();

		(function() {
			var paramTxt = me.request.body;
			var params = paramTxt.split('&');
			for (var i = 0; i < params.length; i++) {
				var param = params[i];
				var paramInfo = param.split('=');
				if (paramInfo.length == 2) {
					if (typeof (me.paramsMap[decode(paramInfo[0])]) == 'undefined') {
						me.paramsMap[decode(paramInfo[0])] = [];
					}
					me.paramsMap[decode(paramInfo[0])]
							.push(decode(paramInfo[1]));
				}
			}
		})();

		me.get = function(key) {
			if (typeof (this.paramsMap[key]) != 'undefined') {
				return this.paramsMap[key][0];
			}
		}

		me.getMethodPath = function() {
			return this['methodPath'];
		}

		me.getRequestPath = function() {
			return this['requestPath'];
		}
	})(req);
}

function buildResponse(res) {
	return new (function(r) {
		this.src = r;
		this.print = function(txt) {
			this.src.event('out', txt);
		}
	})(res);
}

function buildConsole(control) {
	return new (function(c) {
		this.src = c;
		this.execute = function(cmd, params) {
			return this.src.executeCommand(cmd, params);
		}
	})(control);
}

function log(txt) {
	java.lang.System.out.println(txt);
}

function encode(src) {
	return encodeURIComponent(src);
}

function decode(src) {
	return decodeURIComponent(src);
}

function handleRequest(consoleInstance, requestContext, responseHook) {
	var request = buildRequest(requestContext);
	var response = buildResponse(responseHook);
	var console = buildConsole(consoleInstance);
	if (typeof handle != 'undefined') {
		handle(console, request, response);
	} else {
		response.print('缺少handle函数！');
	}
}

java.lang.System.out.println("--加载Server.js成功--");
